plot(p)
rv = {}
for i in (13,39,78,390,1560,23400):
step = m // i
rets = p.iloc[::step].diff().dropna()
_rv = (rets**2).sum()
rv[step] = _rv
np.sqrt(252 * pd.Series(rv))
1800 0.210890 600 0.242003 300 0.209546 60 0.180562 15 0.197455 1 0.200257 dtype: float64
plot_rv()
plot_trans()
plot_trans(zoom=True)
vsp()
vsp_ac1()
plot_sp500(0)
plot_sp500(1)
plot_sp500(2)
plot_sp500(3)
sp500_plot_vsp()
sp500_plot_vsp(zoom=True)
plot_btc_vsp()
plot_btc(0)
plot_btc(1)
plot_btc(2)
summary(HARX(sp500_60s, lags=[1,5,22], rescale=False).fit())
| coef | std err | t | P>|t| | 95.0% Conf. Int. | |
|---|---|---|---|---|---|
| Const | 1.1731e-05 | 5.453e-06 | 2.152 | 3.143e-02 | [1.045e-06,2.242e-05] |
| rv[0:1] | 0.1341 | 0.140 | 0.955 | 0.340 | [ -0.141, 0.409] |
| rv[0:5] | 0.4967 | 0.173 | 2.869 | 4.115e-03 | [ 0.157, 0.836] |
| rv[0:22] | 0.2619 | 0.138 | 1.904 | 5.697e-02 | [-7.765e-03, 0.532] |
summary(HARX(ln_sp500_60s, lags=[1,5,22], rescale=False).fit())
| coef | std err | t | P>|t| | 95.0% Conf. Int. | |
|---|---|---|---|---|---|
| Const | -0.4137 | 9.972e-02 | -4.149 | 3.341e-05 | [ -0.609, -0.218] |
| ln RV[0:1] | 0.5262 | 2.536e-02 | 20.752 | 1.169e-95 | [ 0.477, 0.576] |
| ln RV[0:5] | 0.2933 | 3.159e-02 | 9.284 | 1.632e-20 | [ 0.231, 0.355] |
| ln RV[0:22] | 0.1390 | 2.458e-02 | 5.654 | 1.566e-08 | [9.080e-02, 0.187] |
har_weights()
fcasts = har.forecast(horizon=10)
df = pd.concat([fcasts.mean.iloc[-1], fcasts.variance.iloc[-1]],1)
df.columns = ["Mean","Var"]
df
| Mean | Var | |
|---|---|---|
| h.01 | -8.557239 | 0.271689 |
| h.02 | -8.539637 | 0.366659 |
| h.03 | -8.553043 | 0.413345 |
| h.04 | -8.592687 | 0.446340 |
| h.05 | -8.628181 | 0.477080 |
| h.06 | -8.626100 | 0.510716 |
| h.07 | -8.630428 | 0.539273 |
| h.08 | -8.639355 | 0.563083 |
| h.09 | -8.651733 | 0.583799 |
| h.10 | -8.661265 | 0.602613 |
both = pd.concat([np.exp(df.Mean + df.Var/2), np.exp(df.Mean)],1)
both.columns = ["Log-normal","Median"]
both
| Log-normal | Median | |
|---|---|---|
| h.01 | 0.000220 | 0.000192 |
| h.02 | 0.000235 | 0.000196 |
| h.03 | 0.000237 | 0.000193 |
| h.04 | 0.000232 | 0.000185 |
| h.05 | 0.000227 | 0.000179 |
| h.06 | 0.000232 | 0.000179 |
| h.07 | 0.000234 | 0.000179 |
| h.08 | 0.000235 | 0.000177 |
| h.09 | 0.000234 | 0.000175 |
| h.10 | 0.000234 | 0.000173 |
both.index = np.arange(1,11)
plot(both, 14)
Construct $$\tilde{r}_{t}=\mathrm{\text{sign}}\left(r_{t}\right)\sqrt{RV_{t}} $$
Use standard ARCH model building to construct a model for $\tilde{r}_{t}$
$$\sigma_{t}^{2}=\omega+\alpha_{1}\tilde{r}_{t-1}^{2}+\gamma_{1}\tilde{r}_{t-1}^{2}I_{[\tilde{r}_{t-1}<0]}+\beta_{1}\sigma_{t-1}^{2}$$
becomes
$$\sigma_{t}^{2}=\omega+\alpha_{1}RV_{t-1}+\gamma_{1}RV_{t-1}I_{[r_{t-1}<0]}+\beta_{1}\sigma_{t-1}^{2}$$
from arch import arch_model
res = arch_model(np.sqrt(sp500_60s),mean="zero",o=0, rescale=True).fit(disp="off")
summary(res)
| Mean Model: | Zero Mean | Log-Likelihood: | -3267.13 |
|---|---|---|---|
| Vol Model: | GARCH | AIC: | 6540.26 |
| Distribution: | Normal | BIC: | 6558.30 |
| coef | std err | t | P>|t| | 95.0% Conf. Int. | |
|---|---|---|---|---|---|
| omega | 0.0261 | 4.965e-03 | 5.255 | 1.484e-07 | [1.636e-02,3.582e-02] |
| alpha[1] | 0.7256 | 5.885e-02 | 12.331 | 6.181e-35 | [ 0.610, 0.841] |
| beta[1] | 0.2744 | 5.061e-02 | 5.421 | 5.925e-08 | [ 0.175, 0.374] |
from arch.univariate import HARCH
mod = arch_model(np.sqrt(sp500_60s),mean="zero",o=0, rescale=True)
mod.volatility = HARCH([1,5,22])
res = mod.fit(disp="off")
summary(res)
| Mean Model: | Zero Mean | Log-Likelihood: | -3267.30 |
|---|---|---|---|
| Vol Model: | HARCH | AIC: | 6542.60 |
| Distribution: | Normal | BIC: | 6566.65 |
| coef | std err | t | P>|t| | 95.0% Conf. Int. | |
|---|---|---|---|---|---|
| omega | 0.0305 | 6.020e-03 | 5.073 | 3.909e-07 | [1.874e-02,4.234e-02] |
| alpha[1] | 0.7395 | 5.959e-02 | 12.410 | 2.298e-35 | [ 0.623, 0.856] |
| alpha[5] | 0.1888 | 4.660e-02 | 4.052 | 5.080e-05 | [9.749e-02, 0.280] |
| alpha[22] | 0.0717 | 2.653e-02 | 2.702 | 6.887e-03 | [1.969e-02, 0.124] |
harch_weights()
bsiv()
plot_20()
plot_60()